package com.test.thread;

import java.util.concurrent.LinkedBlockingDeque;

import com.alibaba.fastjson.JSONObject;

public class MayiktThreadMQ {
    /**
     * Broker
     */
    private static LinkedBlockingDeque<JSONObject> broker = new LinkedBlockingDeque<JSONObject>();

    public static void main(String[] args) {
        // 创建生产者线程
        Thread producer = new Thread(new Runnable() {
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(1000);
                        JSONObject data = new JSONObject();
                        data.put("phone", "18611111111");
                        broker.offer(data);
                    } catch (Exception e) {

                    }

                }
            }
        }, "生产者");
        producer.start();
        
        
        // 创建消费者线程
        Thread consumer = new Thread(new Runnable() {
            public void run() {
                while (true) {
                    try {
                        JSONObject data = broker.poll();
                        if (data != null) {
                            System.out.println(Thread.currentThread().getName() + ",获取到数据:" + data.toJSONString());
                        }
                    } catch (Exception e) {

                    }
                }
            }
        }, "消费者");
        consumer.start();
    }
}

